//爆料页面渲染
var voteTpl = {};

/**
 * [tpl2 模板2]
 */
voteTpl.mainHtml = template.compile(
    '	<div id="main" style="background-image:url({{data.background_image||\'./img/bg.png\'}});">' +
    '		<div class="ui-whitespace header">' +
    '			<h2 class="center" style="margin-top:100px">活动主题</h2>' +
    '			<h1 class="center ">{{data.name}}</h1>' +
    '			<div class="rule actDesWrap mt25">' +
    '     			<p class="center actDesTitle">活动规则</p>' +
    '				<div id="actDesBox">{{#data.description}}</div>' +
    '     			<p class="center actDesTitle">活动时间</p>' +
    '				<div class="actDesTimeBox">{{data.start_time}} - {{data.end_time}}</div>' +
    '			</div>' +
    '{{if 0 && data.linked_act_id}}' +
    '       <div class="wybmBox"><a class="wybmBtn"  href="/act/enroll/index.html?act_id={{data.linked_act_id}}">我要报名</a></div>' +
    '{{/if}}' +
    '<i class="wybmArrow"></i></div>' +
    '		<div class="">' +
    '			<ul class="ui-row-flex voteTab mt20 ui-whitespace">' +
    '			    <li class="ui-col ui-flex ui-flex-pack-center cur"><div>投票</div></li>' +
    '			    <li class="ui-col ui-flex ui-flex-pack-center"><div>搜索</div></li>' +
    '			    <li class="ui-col ui-flex ui-flex-pack-center"><div>排行</div></li>' +
    '			</ul>' +
    '			<!-- 投票  S-->' +
    '			<div class="tabList">' +
    '			<div class="container">' +
    '  				<ul class="grid effect-6 votlistBox" id="grid_0"></ul>' +
    '       		<div id="loading">加载中...</div>' +
    '			</div>' +
    '			</div>' +
    '			</div><!-- 投票  E-->' +
    '			<!-- 排行  S-->' +
    '			<div class="tabList pb30" style="display:none;">' +
    '				<div class="search mt20">' +
    '				    <input type="text" class="searchInput">' +
    '					<span class="searchBtn disabled" id="searchBtn">搜索</span>' +
    '				</div>' +
    '			<div class="container">' +
    '  				<ul class="grid effect-6 votlistBox searchBox" id="grid_1"></ul>' +
    '			</div>' +
    '			</div><!-- 搜索  E-->' +
    '			<!-- 排行  S-->' +
    '			<div class="tabList pb30" style="display:none;" >' +
    '			<div class="container">' +
    '  				<ul class="grid effect-6 votlistBox rankBox" id="grid_2"></ul>' +
    '			</div>' +
    '			</div><!-- 排行  E-->' +
    '		</div>' +
    '	</div>');
voteTpl.list = template.compile(
    '{{each data.items as val i}}' +
    '<li>' +
    '    <a>' +
    '      <h3>{{val.title}}</h3>' +
    '      <p><span id="vote1_{{val.id}}">{{if data.scores[val.id] > 0 }}{{data.scores[val.id]}}{{else}}0{{/if}}</span>票</p>' +
    '      <img class="voteBtnItem" voteType="{{val.type}}" voteId = "{{val.id}}" src="{{val.cover_url}}">' +
    '      <span class="voteBtn" voteId = "{{val.id}}" >给TA投票</span>' +
    '  </a>' +
    '</li>' +
    '{{/each}}');

voteTpl.rank = template.compile(
    '{{each data.items as val i}}' +
    '<li class="voteBtnItem" voteId = "{{val.id}}" voteType="{{val.type}}">' +
    '    <a>' +
    '      <img class="voteBtnItem" voteType="{{val.type}}" voteId = "{{val.id}}" src="{{val.cover_url}}">' +
    '		    <div class="ui-list-info">' +
    '	            <h4 class="ui-nowrap">{{val.title}}</h4>' +
    // '	            <p class="ui-nowrap-multi">{{val.content}}</p>' +
    '	            <div class="state">' +
    '	            	<span class="ranking">排名：{{i+1}}</span>' +
    '	            	<span class="votes">{{if data.scores[i] > 0 }}{{data.scores[i]}}{{else}}0{{/if}}票</span>' +
    '	            </div>' +
    '	        </div>' +
    '    </a>' +
    ' </li>' +
    '{{/each}}');

voteTpl.search = template.compile(
    '{{each data as val i}}' +
    '<li class="voteBtnItem" voteId = "{{val.id}}" voteType="{{val.type}}">' +
    '    <a>' +
    '      <img class="voteBtnItem" voteType="{{val.type}}" voteId = "{{val.id}}" src="{{val.cover_url}}">' +
    '		    <div class="ui-list-info">' +
    '	            <h4 class="ui-nowrap">{{val.title}}</h4>' +
    // '	            <p class="ui-nowrap-multi">{{val.content}}</p>' +
    // '	            <div class="state">' +
    // '	            	<span class="ranking">排名：{{i+1}}</span>' +
    // '	            	<span class="votes">{{data.scores[i]}}票</span>' +
    // '	            </div>' +
    '	        </div>' +
    '    </a>' +
    ' </li>' +
    '{{/each}}');

var start_item = '<div class="main" style="background-image:url({{data.background_img||"./img/bg.png"}});background-position:right bottom;">' +
    '               <div class="detailHeader">' +
    '                   <span class="center detailName">{{data.data.item.title}}</span>' +
    '                   <span class="detailNum"><i id="vote_{{data.data.item.id}}">{{if data.data.votes > 0 }}{{data.data.votes}}{{else}}0{{/if}}</i>票</span>' +
    '		            <div id="voteContent" class="mt10">{{#data.data.item.content}}</div>'+
    '                   {{if data.data.item.from!=2}}';
var items1 = '<span class="resource"><img src="{{data.data.item.cover_url}}"/></span>';
var items2 = '<span class="resource audio">' +
    '             <img src="{{data.data.item.cover_url}}"/>' +
    '			  <audio controls src="{{data.data.item.resource_url}}">' +
    '				您的浏览器不能使用最新的视频播放方式呢' +
    '			  </audio>' +
    '          </span>';
var items3 = '<span class="resource">' +
    '            <video poster="{{data.data.item.cover_url}}" src="{{data.data.item.resource_url}}" controls="controls">您的浏览器不支持 video 标签。</video>' +
    '        </span>';
var end_item = '{{/if}}'+
    '       </div>'+
    '       <button class="productionBtn mt20 voteBtn" voteId = "{{data.data.item.id}}">给TA投票</button>' +
    '       <button class="productionBtn mt10 closeItem">返回</button>' +
    '  </div>';

voteTpl.items1 = template.compile(start_item+items1+end_item);
voteTpl.items2 = template.compile(start_item+items2+end_item);
voteTpl.items3 = template.compile(start_item+items3+end_item);

voteTpl.items4 = template.compile(
    '<div id="main" style="background-image:url(\'img/wen.png\');">' +
    '		<div class="ui-whitespace header">' +
    '			<h1 class="center ">“绿地泉”杯4</h1>' +
    '			<h2 class="center">济南市第二届公益广告大赛</h2>' +
    '		</div>' +
    '		<div class="detailCon mt20 pb30">' +
    '			<img src="img/demo1.PNG" alt="">' +
    '			<div class="ui-whitespace">' +
    '				<h2 class="mt20">765号作品 “绿地泉</h2>' +
    '				<p class="mt20">排白杨树像是换了金黄秋装的战士，挺拔的站成一道风景线。夕阳照 在白杨树上，给萧瑟的民大秋天增添了不少暖意。</p>' +
    '				<div class="productionStates mt20">' +
    '					<div>' +
    '						<p>88888票</p>' +
    '						<p>票数</p>' +
    '					</div>' +
    '					<div>' +
    '						<p>123</p>' +
    '						<p>排名</p>' +
    '					</div>' +
    '				</div>' +
    '				<a class="productionBtn mt20 voteBtn" voteId = "{{data.item.id}}">投票</a>' +
    '			</div>' +
    '		</div>' +
    '	</div>');


template.helper('urlFormat', function (url) {
    return encodeURI(url);
});

//是否有背景图,有无背景图显示不一样图标
template.helper('hasImg', function (url) {
    return url ? 'hasImg' : '';
});

//是否有背景图,有无背景图显示不一样图标
template.helper('len', function (url) {
    return url.length;
});

//处理投票类型
//不同类型显示不同图标
template.helper('voteType', function (type) {
    var voteType;
    if (type == 1) { //图片
        voteType = 'picCon'
    } else if (type == 2) { //
        voteType = 'audioCon'
    } else if (type == 3) {
        voteType = 'videoCon'
    } else if (type == 4) {
        voteType = ''
    }
    return voteType
});
